package com.g001.model.GUI;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.enums.MessagePositionType;
import com.g001.model.powers.Action;
import com.g001.model.powers.MessageAction;

public class MessageManager {

	List<Action> messages;
	Action currentMessage;
	
	public MessageManager() throws SlickException {
		messages = new ArrayList<Action>();
	}
	
	public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
		if(currentMessage!=null)
			currentMessage.render(container, game, g);
	}

	public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
		if(currentMessage == null && messages.size()>0) {
			currentMessage = messages.remove(0);
			currentMessage.action();
			currentMessage.update(container, game, delta);
		} else if(currentMessage!=null && currentMessage.isFinished()){
			currentMessage = null;
		}
	}
	
	public void addMessage(Action message){
		messages.add(message);
	}
	
	public void addMessage(String text){
		messages.add(new MessageAction(text, MessagePositionType.CENTER, 2000));
	}
	
	public void addMessage(String text, int fontSize){
		messages.add(new MessageAction(text, MessagePositionType.CENTER, 2000, fontSize));
	}
	
	public void addMessageForPlayer(String text){
		messages.add(new MessageAction(text, MessagePositionType.LEFT));
	}
	
	public void addMessageForOpponent(String text){
		messages.add(new MessageAction(text, MessagePositionType.RIGHT));
	}
	
	
	

}
